import * as types from './mutations-types'

export default {
  // mutations中的方法,尽量只从事单一操作, 复杂的操作放在actions中
  // 商品数量+1
  [types.ADD_GOODS_NUMBER] (state, payload) {
    payload.count += 1
  },

  // 增加商品
  [types.ADD_GOODS_TYPE] (state, payload) {
    // 凡是添加的商品, 为其增加一条done属性, 值为true
    payload.done = true
    state.cartGoodsList.push(payload)
  },

  // 修改单个商品的done状态
  [types.EDIT_GOODS_STATE] (state, iid) {
    state.cartGoodsList.map(t => t.iid === iid && (t.done = !t.done))
  },

  // 修改全部商品的done状态
  [types.EDIT_CHECK_ALL_STATE] (state, checkState) {
    state.cartGoodsList.map(t => (t.done = checkState))
  }
}
